#pragma once

#include <QObject>
#include <QThread>
#include "mecameraworker.h"

class MeCameraManager : public QObject
{
    Q_OBJECT

public:
    static MeCameraManager* getInstance();

    // 相机控制接口
    Q_INVOKABLE void initialize();
    Q_INVOKABLE void startContinuousAcquisition(int intervalMs = 1000);
    Q_INVOKABLE void stopAcquisition();
    Q_INVOKABLE void triggerSingleShot();
    Q_INVOKABLE void disconnectCamera();
    Q_INVOKABLE void connectCamera(const QString& ipAddress);
    Q_INVOKABLE void enumerateDevices();


public:
    // 状态查询
    Q_INVOKABLE bool isCameraConnected() const;
    Q_INVOKABLE bool isAcquiring() const;
    Q_INVOKABLE QString getCameraStatus() const;

signals:
    void initializeRequested();
    void startAcquisitionRequested(int intervalMs);
    void stopAcquisitionRequested();
    void triggerSingleShotRequested();
    void disconnectCameraRequested();
    void connectCameraRequested(const QString& ipAddress);
    void enumerateDevicesRequested();

    // 状态信号
    void cameraOpened(bool success, const QString& message);
    void cameraClosed();
    void acquisitionStarted();
    void acquisitionStopped();
    void frameAcquired(const s_Image3dS& frame);
    void errorOccurred(const QString& errorMessage);
    void devicesEnumerated(const s_DevicesInfo& devicesInfo);


private:
    explicit MeCameraManager(QObject* parent = nullptr);
    ~MeCameraManager();

    static MeCameraManager* m_instance;
    QThread m_workerThread;
    MeCameraWorker* m_worker;
};
